package tothreedesignmodel.interpreter;

/**
 * @author lzhphantom
 * @description
 * @date 创建于 9:57 2020/8/2
 * @modified
 */
public class Context {
    private String[] citys={"上海","成都"};
    private String[] persons={"老人","妇女","儿童"};
    private Expression cityPerson;
    public Context(){
        cityPerson=new AndExpression(new TerminalExpression(citys),new TerminalExpression(persons));
    }
    public  void freeRide(String info){
        boolean ok = cityPerson.interpret(info);
        if (ok){
            System.out.println("你是"+info+",你本次乘车免费");
        }else {
            System.out.println(info+"乘车费3元！");
        }
    }

    public static void main(String[] args) {
        Context bus = new Context();
        bus.freeRide("上海的老人");
        bus.freeRide("上海的年轻人");
        bus.freeRide("成都的老人");
        bus.freeRide("成都的儿童");
        bus.freeRide("成都的小姐姐");
    }
}
